home *** CD-ROM | disk | FTP | other *** search
/ Floppyshop 2 / Floppyshop - 2.zip / Floppyshop - 2.iso / art&graf.ix / art-0039 / spr_des / source / spr_des2.a68 < prev    next >
Text File  |  1997-04-16  |  27KB  |  972 lines

  1.       ORG   0
  2. * Source code to GFA basic, SPRITE DESIGNER
  3. * File: SPR_DES2.A68
  4. * How to use:
  5. *  Poke.B start+0,mode     0-19
  6. *  Poke.B start+1,x        0-31
  7. *  Poke.B start+2,y        0-31
  8. *  Poke.B start+3,color    0-15
  9. *  Poke.B start+4,x_to     0-31
  10. *  Poke.B start+5,y_to     0-31
  11. *  Poke.B start+6,img1     0-15   (image to be edit)
  12. *  Poke.B start+7,img1     0-15   use when Swap Images&Copy Images
  13. *  Poke.W start+8,spritex  0-350
  14. *  Poke.W start+10,spritey 0-230
  15. *  Poke.L start+14,phys          physical screen
  16. *  Poke.L start+18,background    background screen
  17. *  Poke.L start+22,image ptr     ptr to 16 images (512*16 bytes)
  18. *  Call start+30
  19. * Mode:
  20. *   0: Plot x,y,color
  21. *   1: Line x,y,x_to,y_to,color
  22. *   2: Fill x,y,color
  23. *   3: Rotate Left
  24. *   4: Rotate Right
  25. *   5: Rotate Up
  26. *   6: Rotate Down
  27. *   7: Mirror
  28. *   8: Up&Down
  29. *   9: Turn 90'
  30. *  10: Turn 270'
  31. *  11: Clear
  32. *  12: Copy Phys to Background
  33. *  13: Copy Background to Phys (scr3 to scr1&scr2)
  34. *  14: Show sprite
  35. *  15: Move sprite
  36. *  16: Hide sprite
  37. *  17: Swap Images
  38. *  18: Copy Images
  39. *  19: Put image to board
  40. *
  41. ainit equ   $a000
  42. aput  equ   $a001
  43. aget  equ   $a002
  44. abox  equ   $a005
  45. ashow equ   $a009
  46. ahide equ   $a00a
  47. *
  48. mode     equ   0
  49. x1       equ   1
  50. y1       equ   2
  51. color    equ   3
  52. x2       equ   4
  53. y2       equ   5
  54. img1     equ   6
  55. img2     equ   7
  56. sprx     equ   8
  57. spry     equ  10
  58. sprimg   equ  12
  59. scr1     equ  14
  60. scr2     equ  18
  61. imgptr   equ  22
  62. *
  63. var   ds.b  30
  64. *
  65. * start of code...
  66. *
  67. * Initialize & Get address to routine
  68.    lea      var(pc),a3
  69.    dc.w     ainit          ;init line-a
  70.    move.l   a0,a4          ;base address
  71.    move.l   8(a0),a5       ;intin-arrays
  72.    move.l   12(a0),a6      ;ptsin-arrays
  73.    dc.w     ahide          ;hide mouse
  74.    clr.w    $24(a4)        ;writing mode=replace
  75.    lea      fillpat(pc),a0 ;fill pattern
  76.    move.l   a0,$2e(a4)     ; =solid
  77.    move.w   #1,$32(a4)     ;one pattern mask
  78.    clr.w    $34(a4)        ;one color fill
  79.    clr.w    $36(a4)        ;no clipping
  80.    move.b   mode(a3),d0
  81.    tst.b    d0             ;plot?
  82.    beq      plot
  83.    cmp.b    #1,d0          ;line?
  84.    beq      line
  85.    cmp.b    #2,d0          ;fill?
  86.    beq      fill
  87.    cmp.b    #3,d0          ;rotate left?
  88.    beq      left
  89.    cmp.b    #4,d0          ;r. right?
  90.    beq      right
  91.    cmp.b    #5,d0          ;r. up?
  92.    beq      up
  93.    cmp.b    #6,d0          ;r. down?
  94.    beq      down
  95.    cmp.b    #7,d0          ;mirror?
  96.    beq      mirror
  97.    cmp.b    #8,d0          ;up&down?
  98.    beq      updown
  99.    cmp.b    #9,d0          ;turn 90' ?
  100.    beq      turn90
  101.    cmp.b    #10,d0         ;turn 270' ?
  102.    beq      turn270
  103.    cmp.b    #11,d0         ;clear?
  104.    beq      clear
  105.    cmp.b    #12,d0         ;copy phys to background?
  106.    beq      copy1
  107.    cmp.b    #13,d0         ;copy background to phys?
  108.    beq      copy2
  109.    cmp.b    #14,d0         ;Show sprite?
  110.    beq      showspr
  111.    cmp.b    #15,d0         ;Move sprite?
  112.    beq      movespr
  113.    cmp.b    #16,d0         ;Hide sprite?
  114.    beq      hidespr
  115.    cmp.b    #17,d0         ;swap images?
  116.    beq      swapimg
  117.    cmp.b    #18,d0         ;copy images?
  118.    beq      copyimg
  119.    cmp.b    #19,d0         ;put image to board?
  120.    beq      putimg
  121. *
  122. *
  123. exit move   #0,0(a5)
  124.    dc.w     ashow
  125.    rts                     'return to Basic
  126. *
  127. *  used by program
  128. * Get image from board (pos. 256,144)
  129. getimg move #9,d1
  130.    move.l   imgptr(a3),a0  ;ptr to 16 images
  131.    clr      d0
  132.    move.b   img1(a3),d0    ;edit image
  133.    lsl      d1,d0          ;each image 512 bytes
  134.    lea      0(a0,d0.w),a0  ;address to current image
  135.    move.l   scr1(a3),a1    ;physical screen
  136.    add.l    #23168,a1      ;pos. 256,144
  137.    move     #31,d0         ;32 lines
  138. getl move.l (a1)+,(a0)+    ;copy from screen to image
  139.    move.l   (a1)+,(a0)+
  140.    move.l   (a1)+,(a0)+
  141.    move.l   (a1)+,(a0)+
  142.    add.l    #144,a1        ;next line
  143.    dbf      d0,getl
  144.    rts
  145. *   used by program
  146. * Set color ,color in D2
  147. setcolor move.w d2,0(a5)
  148.    clr.l    $18(a4)
  149.    clr.l    $1c(a4)
  150.    btst     #0,d2
  151.    beq      bp0
  152.    move.w   #1,$18(a4)
  153. bp0   btst  #1,d2
  154.    beq      bp1
  155.    move.w   #1,$1a(a4)
  156. bp1   btst  #2,d2
  157.    beq      bp2
  158.    move.w   #1,$1c(a4)
  159. bp2   btst  #3,d2
  160.    beq      bp3
  161.    move.w   #1,$1e(a4)
  162. bp3   rts
  163. *
  164. * (used by fill,rotate...)
  165. * Get a Point from screen (looking in small box)
  166. * In: D0=x D1=y  Out:D3=color
  167. point movem.l  d0/d1/d2,-(a7)
  168.    add      #256,d0
  169.    add      #144,d1
  170.    move     d0,0(a6)
  171.    move     d1,2(a6)
  172.    dc.w     aget
  173.    move     d0,d3
  174.    movem.l   (a7)+,d0/d1/d2
  175.    rts
  176. * Plot a point: Big Point & Small Point
  177. plot clr.w  d0
  178.    clr.w    d1
  179.    move.b   x1(a3),d0
  180.    move.b   y1(a3),d1
  181.    move.b   color(a3),d2
  182.    bsr      setcolor
  183.    bsr      plot0
  184.    bsr      getimg      ;new image
  185.    bra      exit
  186. *
  187. * Plot0 (used by plot,line,fill...)
  188. * d0=x,d1=y (color is set!)
  189. plot0 movem.l   d0/d1/d2/d3/d4,-(a7)
  190. *plot on small board
  191.    move.w   d0,d3          ;save x&y
  192.    move.w   d1,d4
  193.    add.w    #256,d0
  194.    add.w    #144,d1
  195.    move.w   d0,0(a6)
  196.    move.w   d1,2(a6)
  197.    dc.w     aput           ;plot x+256,y+144
  198. *plot on big board  box 6x+1,6y+1,6x+5,6y+5
  199.    mulu     #6,d3
  200.    mulu     #6,d4
  201.    addq.w   #1,d3
  202.    addq.w   #1,d4
  203.    move.w   d3,$26(a4)     ;6*x+1
  204.    move.w   d4,$28(a4)     ;6*y+1
  205.    addq.w   #4,d3
  206.    addq.w   #4,d4
  207.    move.w   d3,$2a(a4)     ;6*x+5
  208.    move.w   d4,$2c(a4)     ;6*y+5
  209.    dc.w     abox           ;filled rectangle
  210.    movem.l  (a7)+,d0/d1/d2/d3/d4
  211.    rts
  212. *
  213. * Line
  214. *
  215. line  move.b   color(a3),d2
  216.    bsr      setcolor
  217.    lea      local(pc),a0
  218.    clr.l    d0
  219.    clr.l    d1
  220.    clr.l    d2
  221.    clr.l    d3
  222.    move.b   x1(a3),d0             ;x1
  223.    move.b   y1(a3),d1             ;y1
  224.    move.b   x2(a3),d2            ;x2
  225.    move.b   y2(a3),d3            ;y2
  226.    move     d2,d7
  227.    sub      d0,d7
  228.    move     d7,dx(a0)            ;dx=x2-x1
  229.    move     #1,sdx(a0)           ;count sgn(dx) & abs(dx)...
  230.    tst      d7
  231.    bpl      dxplus
  232.    neg      d7
  233.    move     #$ffff,sdx(a0)
  234. dxplus   move  d7,adx(a0)
  235.    move     d3,d7
  236.    sub      d1,d7
  237.    move     d7,dy(a0)            ;dy=y2-y1
  238.    move     #1,sdy(a0)           ;count sgn(dy) & abs(dy)...
  239.    tst      d7
  240.    bpl      dyplus
  241.    neg      d7
  242.    move     #$ffff,sdy(a0)
  243. dyplus   move  d7,ady(a0)
  244.    cmp      adx(a0),d7           ;abs(dx)=abs(dy)?
  245.    bne      dynodx               ;no
  246.    move     sdx(a0),d2           ;xstep= -1,0 or +1
  247.    swap     d2
  248.    move     sdy(a0),d3           ;ystep= -1,0 or +1
  249.    swap     d3
  250.    bra      draw
  251. dynodx   bge   dybigdx           ;abs(dy)>=abs(dx)?
  252.    move     adx(a0),d7
  253.    move     sdx(a0),d2           ;xstep= -1,0 or +1
  254.    swap     d2
  255.    move     ady(a0),d3
  256.    swap     d3
  257.    divu     d7,d3                ;ystep= abs(dy)/abs(dx) ( *sgn(dy) )
  258.    and.l    #$ffff,d3
  259.    tst      sdy(a0)
  260.    bpl      draw
  261.    neg.l    d3
  262.    bra      draw
  263. dybigdx  move  ady(a0),d7
  264.    move     sdy(a0),d3           ;ystep= -1,0 or +1
  265.    swap     d3
  266.    move     adx(a0),d2           ;xstep= abs(dx)/abs(dy) ( *sgn(dx) )
  267.    swap     d2
  268.    divu     d7,d2
  269.    and.l    #$ffff,d2
  270.    tst      sdx(a0)
  271.    bpl      draw
  272.    neg.l    d2
  273. draw     swap  d0
  274.    swap     d1
  275.    move     #$8000,d0
  276.    move     #$8000,d1
  277.    swap     d0
  278.    swap     d1
  279. lloop    bsr   plot0
  280.    swap     d0
  281.    swap     d1
  282.    add.l    d2,d0
  283.    add.l    d3,d1
  284.    swap     d0
  285.    swap     d1
  286.    dbf      d7,lloop
  287.    bsr      getimg      ;update image
  288.    bra      exit
  289. *
  290. * Fill
  291. fill     move.b   color(a3),d2
  292.    clr      d0
  293.    clr      d1
  294.    move.b   x1(a3),d0
  295.    move.b   y1(a3),d1
  296.    bsr      setcolor
  297.    bsr      point       ;color at x,y in D3
  298.    move     d3,d4
  299.    cmp.b    d2,d4       ;fill color=background color?
  300.    beq      fillend
  301.    bsr      fill0
  302. fillend bsr getimg      ;update image
  303.    bra      exit
  304. fill0    bsr   point
  305.    cmp.b    d3,d4       ;another color than background?
  306.    bne      noysub      ;yes  (exit)
  307.    bsr      plot0
  308.    cmp      #30,d0      ;x>30?
  309.    bhi      noxadd      ;yes
  310.    addq     #1,d0       ;try fill x+1,y
  311.    bsr      fill0
  312.    subq     #1,d0
  313. noxadd   cmp   #30,d1   ;y>30?
  314.    bhi      noyadd      ;yes
  315.    addq     #1,d1       ;try fill x,y+1
  316.    bsr      fill0
  317.    subq     #1,d1
  318. noyadd   tst   d0       ;x=0?
  319.    beq      noxsub      ;yes
  320.    subq     #1,d0       ;try fill x-1,y
  321.    bsr      fill0
  322.    addq     #1,d0
  323. noxsub   tst   d1       ;y=1?
  324.    beq      noysub      ;yes
  325.    subq     #1,d1       ;try fill x,y-1
  326.    bsr      fill0
  327.    addq     #1,d1
  328. noysub   rts
  329. *
  330. * Rotate Left
  331. left  move     #31,d1   ;y=31 to 0
  332. rotly clr      d0       ;x=0 to 30
  333. rotlx addq     #1,d0    ;get color from x+1,y
  334.       bsr      point
  335.       subq     #1,d0
  336.       move     d3,d2    ;and plot it at x,y
  337.       bsr      setcolor
  338.       bsr      plot0
  339.       addq     #1,d0
  340.       cmp      #31,d0
  341.       bne      rotlx    ;next x
  342.       clr      d2
  343.       bsr      setcolor
  344.       bsr      plot0    ;rotate in color 0
  345.       dbf      d1,rotly ;next y
  346.       bsr      getimg   ;update image
  347.       bra      exit
  348. *
  349. * Rotate Right
  350. right move     #31,d1   ;y=31 to 0
  351. rotry move     #31,d0   ;x=31 to 1
  352. rotrx subq     #1,d0    ;get color from x-1,y
  353.       bsr      point
  354.       addq     #1,d0
  355.       move     d3,d2    ;and plot it at x,y
  356.       bsr      setcolor
  357.       bsr      plot0
  358.       subq     #1,d0
  359.       tst      d0
  360.       bne      rotrx    ;next x
  361.       clr      d2
  362.       bsr      setcolor
  363.       bsr      plot0    ;rotate in color 0
  364.       dbf      d1,rotry ;next y
  365.       bsr      getimg   ;update image
  366.       bra      exit
  367. *
  368. * Rotate Up
  369. up    move     #31,d0   ;x=31 to 0
  370. rotux clr      d1       ;y=0 to 30
  371. rotuy addq     #1,d1    ;get color from x,y+1
  372.       bsr      point
  373.       subq     #1,d1
  374.       move     d3,d2    ;and plot it at x,y
  375.       bsr      setcolor
  376.       bsr      plot0
  377.       addq     #1,d1
  378.       cmp      #31,d1
  379.       bne      rotuy    ;next y
  380.       clr      d2
  381.       bsr      setcolor
  382.       bsr      plot0    ;rotate in color 0
  383.       dbf      d0,rotux ;next x
  384.       bsr      getimg   ;update image
  385.       bra      exit
  386. *
  387. * Rotate Down
  388. down  move     #31,d0   ;x=31 to 0
  389. rotdx move     #31,d1   ;y=31 to 1
  390. rotdy subq     #1,d1    ;get color from x,y-1
  391.       bsr      point
  392.       addq     #1,d1
  393.       move     d3,d2    ;and plot it at x,y
  394.       bsr      setcolor
  395.       bsr      plot0
  396.       subq     #1,d1
  397.       tst      d1
  398.       bne      rotdy    ;next y
  399.       clr      d2
  400.       bsr      setcolor
  401.       bsr      plot0    ;rotate in color 0
  402.       dbf      d0,rotdx ;next x
  403.       bsr      getimg   ;update image
  404.       bra      exit
  405. *
  406. * Mirror
  407. mirror move    #31,d1   ;y=31 to 0
  408. miry  move     #15,d0   ;x=15 to 0
  409. mirx  bsr      point    ;color at x,y
  410.       move     d3,d4
  411.       eor      #31,d0
  412.       bsr      point    ;color at 31-x,y
  413.       move     d3,d5
  414.       move     d4,d2
  415.       bsr      setcolor ;first color
  416.       bsr      plot0    ; plot at 31-x,y
  417.       eor      #31,d0
  418.       move     d5,d2
  419.       bsr      setcolor ;second color
  420.       bsr      plot0    ; plot at x,y
  421.       dbf      d0,mirx  ;next x
  422.       dbf      d1,miry  ;next y
  423.       bsr      getimg   ;update image
  424.       bra      exit
  425. *
  426. * Up & Down
  427. updown move    #31,d0   ;x=31 to 0
  428. updox move     #15,d1   ;y=15 to 0
  429. updoy bsr      point    ;color at x,y
  430.       move     d3,d4
  431.       eor      #31,d1
  432.       bsr      point    ;color at x,31-y
  433.       move     d3,d5
  434.       move     d4,d2
  435.       bsr      setcolor ;first color
  436.       bsr      plot0    ; plot at x,31-y
  437.       eor      #31,d1
  438.       move     d5,d2
  439.       bsr      setcolor ;second color
  440.       bsr      plot0    ; plot at x,y
  441.       dbf      d1,updoy
  442.       dbf      d0,updox
  443.       bsr      getimg   ;update image
  444.       bra      exit
  445. *
  446. * Turn 90'
  447. turn90   clr   d1
  448. t90y  clr      d0
  449. t90x  bsr      point
  450.       move     d3,d4
  451.       move     d0,d7
  452.       move     d1,d0
  453.       move     d7,d1
  454.       eor      #31,d0
  455.       bsr      point
  456.       move     d3,d2
  457.       eor      #31,d0
  458.       move     d0,d7
  459.       move     d1,d0
  460.       move     d7,d1
  461.       bsr      setcolor
  462.       bsr      plot0
  463.       eor      #31,d0
  464.       eor      #31,d1
  465.       bsr      point
  466.       move     d3,d2
  467.       move     d0,d7
  468.       move     d1,d0
  469.       move     d7,d1
  470.       eor      #31,d1
  471.       bsr      setcolor
  472.       bsr      plot0
  473.       eor      #31,d0
  474.       eor      #31,d1
  475.       bsr      point
  476.       move     d3,d2
  477.       move     d0,d7
  478.       move     d1,d0
  479.       move     d7,d1
  480.       eor      #31,d1
  481.       bsr      setcolor
  482.       bsr      plot0
  483.       move     d0,d7
  484.       move     d1,d0
  485.       move     d7,d1
  486.       eor      #31,d0
  487.       move     d4,d2
  488.       bsr      setcolor
  489.       bsr      plot0
  490.       move     d0,d7
  491.       move     d1,d0
  492.       move     d7,d1
  493.       eor      #31,d0
  494.       addq     #1,d0
  495.       cmp      #16,d0
  496.       bne      t90x
  497.       addq     #1,d1
  498.       cmp      #16,d1
  499.       bne      t90y
  500.       bsr      getimg   ;update image
  501.       bra      exit
  502. *
  503. * Turn 270'
  504. turn270 clr    d1
  505. t270y clr      d0
  506. t270x bsr      point
  507.       move     d3,d4
  508.       move     d0,d7
  509.       move     d1,d0
  510.       move     d7,d1
  511.       eor      #31,d1
  512.       bsr      point
  513.       move     d3,d2
  514.       move     d0,d7
  515.       move     d1,d0
  516.       move     d7,d1
  517.       eor      #31,d0
  518.       bsr      setcolor
  519.       bsr      plot0
  520.       eor      #31,d0
  521.       eor      #31,d1
  522.       bsr      point
  523.       move     d3,d2
  524.       eor      #31,d1
  525.       move     d0,d7
  526.       move     d1,d0
  527.       move     d7,d1
  528.       bsr      setcolor
  529.       bsr      plot0
  530.       eor      #31,d0
  531.       eor      #31,d1
  532.       bsr      point
  533.       move     d3,d2
  534.       eor      #31,d1
  535.       move     d0,d7
  536.       move     d1,d0
  537.       move     d7,d1
  538.       bsr      setcolor
  539.       bsr      plot0
  540.       eor      #31,d0
  541.       move     d0,d7
  542.       move     d1,d0
  543.       move     d7,d1
  544.       move     d4,d2
  545.       bsr      setcolor
  546.       bsr      plot0
  547.       eor      #31,d0
  548.       move     d0,d7
  549.       move     d1,d0
  550.       move     d7,d1
  551.       addq     #1,d0
  552.       cmp      #16,d0
  553.       bne      t270x
  554.       addq     #1,d1
  555.       cmp      #16,d1
  556.       bne      t270y
  557.       bsr      getimg      ;update image
  558.       bra      exit
  559. *
  560. * Clear
  561. clear clr      d2
  562.       bsr      setcolor
  563.       move     #31,d1   ;y=31 to 0
  564. clry  move     #31,d0   ;x=31 to 0
  565. clrx  bsr      plot0    ;clear
  566.       dbf      d0,clrx
  567.       dbf      d1,clry
  568.       bsr      getimg   ;update image
  569.       bra      exit
  570. *
  571. * Put image (move image from memory to big board)
  572. putimg move    #9,d1
  573.       move.l   imgptr(a3),a0     ;address to 16 images
  574.       clr      d0
  575.       move.b   img1(a3),d0       ;image to be putted
  576.       lsl      d1,d0             ;each image 512 bytes
  577.       lea      0(a0,d0.w),a0     ;address to current image
  578.       move.l   scr1(a3),a1       ;physbase
  579.       add.l    #23168,a1         ;pos 256,144
  580.       move     #31,d0            ;32 lines
  581. putl  move.l   (a0)+,(a1)+       ;copy from memory to screen
  582.       move.l   (a0)+,(a1)+
  583.       move.l   (a0)+,(a1)+
  584.       move.l   (a0)+,(a1)+
  585.       add.l    #144,a1           ;next line
  586.       dbf      d0,putl
  587.       move     #31,d0            ;x=31 to 0
  588. putlx move     #31,d1            ;y=31 to 0
  589. putly bsr      point             ;get color value to d3 (from little board)
  590.       move     d3,d2
  591.       bsr      setcolor
  592.       bsr      plot0             ;plot on big board (& little board)
  593.       dbf      d1,putly
  594.       dbf      d0,putlx
  595.       bra      exit
  596. *
  597. * Copy physbase to background
  598. copy1 move.l scr1(a3),a0         ;physbase
  599.       move.l   scr2(a3),a1       ;background
  600.       move     #8000,d0          ;8000 long words
  601. copy  move.l   (a0)+,(a1)+       ;copy
  602.       dbf      d0,copy
  603.       bra      exit
  604. *
  605. * Copy background to physbase
  606. copy2 move.l   scr2(a3),a0
  607.       move.l   scr1(a3),a1
  608.       move     #8000,d0
  609.       bra      copy
  610. *
  611. * Copy images img1 to img2
  612. copyimg move   #9,d1
  613.       move.l   imgptr(a3),a0  :\start of image area
  614.       clr      d0
  615.       move.b   img1(a3),d0
  616.       lsl      d1,d0          :\each image 512 bytes
  617.       add.l    d0,a0          :\ptr to image 1 
  618.       move.l   imgptr(a3),a1
  619.       clr      d0
  620.       move.b   img2(a3),d0
  621.       lsl      d1,d0
  622.       add.l    d0,a1          :\ptr to image 2
  623.       move     #31,d0         :\32 lines
  624. copyl move.l   (a0)+,(a1)+
  625.       move.l   (a0)+,(a1)+
  626.       move.l   (a0)+,(a1)+
  627.       move.l   (a0)+,(a1)+
  628.       dbf      d0,copyl
  629.       bra      exit
  630. *
  631. * Swap images
  632. swapimg move   #9,d1
  633.       move.l   imgptr(a3),a0  :\start of image area
  634.       clr      d0
  635.       move.b   img1(a3),d0
  636.       lsl      d1,d0          :\each image 512 bytes
  637.       add.l    d0,a0          :\ptr to image 1
  638.       move.l   imgptr(a3),a1
  639.       clr      d0
  640.       move.b   img2(a3),d0
  641.       lsl      d1,d0
  642.       add.l    d0,a1          :\ptr to image 2
  643.       move     #31,d0         :\32 lines
  644. swapl move.l   0(a0),d1
  645.       move.l   4(a0),d2
  646.       move.l   8(a0),d3
  647.       move.l   12(a0),d4
  648.       move.l   0(a1),(a0)+
  649.       move.l   4(a1),(a0)+
  650.       move.l   8(a1),(a0)+
  651.       move.l   12(a1),(a0)+
  652.       move.l   d1,(a1)+
  653.       move.l   d2,(a1)+
  654.       move.l   d3,(a1)+
  655.       move.l   d4,(a1)+
  656.       dbf      d0,swapl
  657.       bra      exit
  658. *
  659. * Show sprite
  660. showspr bsr    dospr
  661.         bra    exit
  662. *
  663. * Move sprite
  664. movespr bsr    unspr
  665.       bsr      dospr
  666.       bra      exit
  667. *
  668. * Hide sprite
  669. hidespr bsr    unspr
  670.       bra      exit
  671. *
  672. * Erase sprite (used by program)
  673. unspr lea      local(pc),a2
  674.       move.l   sproff(a2),d0  :\offset to screen
  675.       move.l   scr1(a3),a0    :\physbase
  676.       move.l   scr2(a3),a1    :\background
  677.       add.l    d0,a0
  678.       add.l    d0,a1
  679.       move     sprheight(a2),d1 :\visible sprite height-1
  680.       move     sprwidth(a2),d0  :\x-words saved
  681.       cmp      #1,d0          :\16 pixel saved?
  682.       beq      un16
  683.       cmp      #2,d0          :\32 pixel saved?
  684.       beq      un32           :\ else 48 pixel saved!
  685. un48  move.l  (a1)+,(a0)+     :\copy 48 pixel*4 planes=24 bytes
  686.       move.l   (a1)+,(a0)+
  687.       move.l   (a1)+,(a0)+
  688.       move.l   (a1)+,(a0)+
  689.       move.l   (a1)+,(a0)+
  690.       move.l   (a1)+,(a0)+
  691.       add.l    #136,a0        :\next line
  692.       add.l    #136,a1
  693.       dbf      d1,un48
  694.       rts
  695. un32  move.l   (a1)+,(a0)+    :\copy 32 pixel*4 planes=16 bytes
  696.       move.l   (a1)+,(a0)+
  697.       move.l   (a1)+,(a0)+
  698.       move.l   (a1)+,(a0)+
  699.       add.l    #144,a0        :\next line
  700.       add.l    #144,a1
  701.       dbf      d1,un32
  702.       rts
  703. un16  move.l   (a1)+,(a0)+    :\copy 16pixel*4 planes=8 bytes
  704.       move.l   (a1)+,(a0)+
  705.       add.l    #152,a0        :\next line
  706.       add.l    #152,a1
  707.       dbf      d1,un16
  708.       rts
  709. *
  710. * Draw sprite (used by program)
  711. dospr lea      local(pc),a2
  712.       move     #9,d1
  713.       move.l   imgptr(a3),a1
  714.       clr      d0
  715.       move.b   sprimg(a3),d0
  716.       lsl      d1,d0
  717.       add.l    d0,a1          :\image pointer
  718.       move     sprx(a3),d0    :\sprite-x
  719.       move     spry(a3),d1    :\sprite-y
  720.       cmp      #350,d0        :\x out of range?  (0-350)
  721.       bhi      doexit
  722.       cmp      #230,d1        :\y out of range?  (0-230)
  723.       bhi      doexit
  724. *
  725.       move.l   #0,a0          :\offset on screen (inc. later)
  726. *
  727.       cmp      #30,d1         :\sprite at top?
  728.       bhi      donotop
  729.       move     d1,d2          :\#lines-1=y0
  730.       eor      #31,d1         :\start=31-y0
  731.       bra      doyok
  732. donotop cmp    #199,d1        :\sprite in middle?
  733.       bhi      donomiddle
  734.       move     d1,d7          :\screen=y0-31
  735.       sub      #31,d7
  736.       mulu     #160,d7
  737.       add.w    d7,a0          :\inc. screen offset
  738.       clr      d1             :\start=0
  739.       move     #31,d2         :\#lines-1=31
  740.       bra      doyok
  741. donomiddle move d1,d7         :\screen=y0-31
  742.       sub      #31,d7
  743.       mulu     #160,d7
  744.       add.w    d7,a0          :\inc. screen offset
  745.       move     d1,d2          :\#lines-1=31-(y0-199)
  746.       sub      #199,d2
  747.       eor      #31,d2
  748.       clr      d1             :\start=0
  749. doyok move     d2,sprheight(a2) :\save height-1
  750.       lsl      #4,d1          :\adjust image ptr
  751.       lea      0(a1,d1.w),a1   :\ to current sprite height
  752.       cmp      #14,d0         :\sprite on left side?
  753.       bhi      nol1
  754. *Sprite on the left side (0-50%)
  755.       move     #1,sprwidth(a2)       :\save x-words (16 pixel)
  756.       move.l   a0,sproff(a2)  :\save screen offset
  757.       add.l    scr1(a3),a0    :\physbase+offset
  758.       and      #15,d0         :\x MOD 15=rotations
  759.       addq     #1,d0          :\at least one pixel visible
  760.       addq.l   #8,a1          :\skip left side of sprite
  761. dloop1 bsr     pixleft
  762.       add.l    #160,a0        :\next line
  763.       add.l    #8,a1          :\skip left side
  764.       dbf      d2,dloop1
  765.       bra      doexit
  766. nol1  cmp      #30,d0         :\sprite on left side?
  767.       bhi      nol2
  768. *Sprite on the left side (50-100%)
  769.       move     #2,sprwidth(a2)       :\save x-words (32 pixel)
  770.       move.l   a0,sproff(a2)       :\save screen offset
  771.       add.l    scr1(a3),a0          :\physbase+offset
  772.       sub      #15,d0         :\begin x=0
  773.       and      #15,d0         :\rotations
  774. dloop2 bsr     pixleft
  775.       bsr      pix16
  776.       add.l    #160,a0        :\next line
  777.       dbf      d2,dloop2
  778.       bra      doexit
  779. nol2  cmp      #319,d0        :\sprite in the middle (x)
  780.       bhi      nocenter
  781. *Sprite in the middle
  782.       move     #3,sprwidth(a2)       :\save x-words (48 pixel)
  783.       sub      #31,d0         :\begin x=0
  784.       move     d0,d3
  785.       and      #15,d0         :\rotations
  786.       lsr      #4,d3          :\x-byte=4*(x DIV 16)
  787.       lsl      #3,d3
  788.       lea      0(a0,d3.w),a0  :\inc. screen offset
  789.       move.l   a0,sproff(a2)  :\save screen offset
  790.       add.l    scr1(a3),a0    :\physbase+offset
  791. dloop3 bsr     pix16
  792.       add.l    #8,a0          :\next 16 pixel
  793.       bsr      pix16
  794.       add.l    #152,a0        :\next line
  795.       dbf      d2,dloop3
  796.       bra      doexit
  797. nocenter cmp   #335,d0        :\sprite on right side?
  798.       bhi      doright2
  799. *Sprite on the right side (50-100%)
  800.       move     #2,sprwidth(a2)       :\save x-words (32 pixel)
  801.       add.l    #144,a0        :\inc. screen offset
  802.       move.l   a0,sproff(a2)  :\save screen offset
  803.       add.l    scr1(a3),a0    :\physbase+offset
  804.       sub      #320,d0        :\begin x=0
  805.       and      #15,d0         :\rotations
  806.       addq     #1,d0          :\at least one pixel visible
  807. dloop4 bsr     pix16
  808.       add.l    #8,a0          :\next 16 pixel
  809.       bsr      pixright
  810.       add.l    #152,a0        :\next line
  811.       dbf      d2,dloop4
  812.       bra      doexit
  813. *Sprite on the right side (0-50%)
  814. doright2 move  #1,sprwidth(a2)      :\save x-words (16 pixel)
  815.       add.l    #152,a0        :\inc. screen offset
  816.       move.l   a0,sproff(a2)      :\save screen offset
  817.       add.l    scr1(a3),a0          :\phybase+offset
  818.       sub      #336,d0        :\begin x=0
  819.       and      #15,d0         :\rotations
  820.       addq     #1,d0          :\at least one pixel visible
  821. dloop5 bsr     pixright
  822.       add.l    #8,a1          :\skip right side on sprite
  823.       add.l    #160,a0        :\next line
  824.       dbf      d2,dloop5
  825. doexit rts
  826. *
  827. pix16 MOVE (A1)+,D4           :\get sprite data
  828.    MOVE   (A1)+,D5            :\4planes a 16 pixel
  829.    MOVE   (A1)+,D6
  830.    MOVE   (A1)+,D7
  831.    SWAP   D4                  :\sprite in high word
  832.    SWAP   D5
  833.    SWAP   D6
  834.    SWAP   D7
  835.    CLR    D4                  :\clear low word
  836.    CLR    D5
  837.    CLR    D6
  838.    CLR    D7
  839.    LSR.L  D0,D4               :\rotate D0 times
  840.    LSR.L  D0,D5
  841.    LSR.L  D0,D6
  842.    LSR.L  D0,D7
  843. *make a mask (color 0=transparent)
  844.    MOVE.L D4,D3
  845.    OR.L   D5,D3
  846.    OR.L   D6,D3
  847.    OR.L   D7,D3
  848. *mask sprite data
  849.    AND.L  D3,D4
  850.    AND.L  D3,D5
  851.    AND.L  D3,D6
  852.    AND.L  D3,D7
  853. *mask screen
  854.    NOT.L  D3
  855.    AND    D3,$8(A0)
  856.    AND    D3,$A(A0)
  857.    AND    D3,$C(A0)
  858.    AND    D3,$E(A0)
  859.    SWAP   D3
  860.    AND    D3,$0(A0)
  861.    AND    D3,$2(A0)
  862.    AND    D3,$4(A0)
  863.    AND    D3,$6(A0)
  864.    SWAP   D3
  865. *add screen with sprite
  866.    ADD    D4,$8(A0)
  867.    ADD    D5,$A(A0)
  868.    ADD    D6,$C(A0)
  869.    ADD    D7,$E(A0)
  870.    SWAP   D4
  871.    SWAP   D5
  872.    SWAP   D6
  873.    SWAP   D7
  874.    ADD    D4,$0(A0)
  875.    ADD    D5,$2(A0)
  876.    ADD    D6,$4(A0)
  877.    ADD    D7,$6(A0)
  878.    rts
  879. *
  880. pixleft MOVE (A1)+,D4          :\get sprite data
  881.    MOVE   (A1)+,D5             :\4planes a 16 pixel
  882.    MOVE   (A1)+,D6
  883.    MOVE   (A1)+,D7
  884.    SWAP   D4                   :\sprite in high word
  885.    SWAP   D5
  886.    SWAP   D6
  887.    SWAP   D7
  888.    CLR    D4                   :\clear low word
  889.    CLR    D5
  890.    CLR    D6
  891.    CLR    D7
  892.    LSR.L  D0,D4                :\rotate D0 times
  893.    LSR.L  D0,D5
  894.    LSR.L  D0,D6
  895.    LSR.L  D0,D7
  896. *make a mask (color 0=transparent)
  897.    MOVE   D4,D3
  898.    OR     D5,D3
  899.    OR     D6,D3
  900.    OR     D7,D3
  901. *mask sprite data(uses only bit0-15)
  902.    AND    D3,D4
  903.    AND    D3,D5
  904.    AND    D3,D6
  905.    AND    D3,D7
  906. *mask screen
  907.    NOT    D3
  908.    AND    D3,$0(A0)
  909.    AND    D3,$2(A0)
  910.    AND    D3,$4(A0)
  911.    AND    D3,$6(A0)
  912. *add screen with sprite
  913.    ADD    D4,$0(A0)
  914.    ADD    D5,$2(A0)
  915.    ADD    D6,$4(A0)
  916.    ADD    D7,$6(A0)
  917.    rts
  918. *
  919. pixright MOVE (A1)+,D4       :\get sprite data
  920.    MOVE   (A1)+,D5           :\4planes a 16 pixel
  921.    MOVE   (A1)+,D6
  922.    MOVE   (A1)+,D7
  923.    SWAP   D4                 :\sprite in high word
  924.    SWAP   D5
  925.    SWAP   D6
  926.    SWAP   D7
  927.    LSR.L  D0,D4              :\rotate D0 times
  928.    LSR.L  D0,D5
  929.    LSR.L  D0,D6
  930.    LSR.L  D0,D7
  931.    SWAP   D4                 :\sprite in low word
  932.    SWAP   D5
  933.    SWAP   D6
  934.    SWAP   D7
  935. *make a mask (color 0=transparent)
  936.    MOVE   D4,D3
  937.    OR     D5,D3
  938.    OR     D6,D3
  939.    OR     D7,D3
  940. *mask sprite data
  941.    AND    D3,D4
  942.    AND    D3,D5
  943.    AND    D3,D6
  944.    AND    D3,D7
  945. *mask screen
  946.    NOT    D3
  947.    AND    D3,$0(A0)
  948.    AND    D3,$2(A0)
  949.    AND    D3,$4(A0)
  950.    AND    D3,$6(A0)
  951. *add screen with sprite
  952.    ADD    D4,$0(A0)
  953.    ADD    D5,$2(A0)
  954.    ADD    D6,$4(A0)
  955.    ADD    D7,$6(A0)
  956.    rts
  957. *
  958. fillpatt  dc.w  $ffff,$ffff
  959. local    ds.w   30
  960. dx    equ   0
  961. dy    equ   2
  962. sdx   equ   4
  963. sdy   equ   6
  964. adx   equ   8
  965. ady   equ   10
  966. sproff    equ  12
  967. sprwidth  equ  16
  968. sprheight equ  18
  969. *
  970.    end
  971.